cmake_minimum_required(VERSION 3.5.0)

project(quad_remote_controller)

set(CMAKE_BUILD_TYPE
	Debug
)

add_definitions(
	-Wall
	-Wno-unused-result
	-g
	-Os
	-fno-inline
	-rdynamic
	-funwind-tables
	-ffunction-sections 
	)

set(STD_LIBS
	m
	pthread
	readline
	history
	ncurses
)

if ("${CC4TARGET}" STREQUAL "x86_64")
	message(STATUS "Compile to x86_64.")
	add_definitions(-D CONFIG_TAR4X86_64)
elseif("${CC4TARGET}" STREQUAL "arm")
	message(STATUS "Compile to arm.")
	add_definitions(-D CONFIG_TAR4ARM)
elseif("${CC4TARGET}" STREQUAL "arm64")
	message(STATUS "Compile to arm64.")
	add_definitions(-D CONFIG_TAR4ARM64)
else()
	message(STATUS "Unknow compile target.")
endif()

message("-- ToolChain: " ${CMAKE_TOOLCHAIN_FILE})

#查找所有.h头文件
file(GLOB_RECURSE 
	SOURCES_DIR
	RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
	CONFIGURE_DEPENDS 
	src/*.h src/*.hpp
)

#从.h文件中剥离出其所在的目录
foreach(src ${SOURCES_DIR})
	string(FIND ${src} "/" LastIndex REVERSE)
	string(SUBSTRING ${src} 0 ${LastIndex} inc)
	list(APPEND PATH_INCS ${inc})
endforeach(src)

#头文件包含路径
include_directories(
	#build
	${PROJECT_BINARY_DIR}
	${PROJECT_BINARY_DIR}/py_cpp
	#inc
	${PROJECT_SOURCE_DIR}/inc
	#src
	${PATH_INCS}
	#libs
	${PROJECT_SOURCE_DIR}/libs/${CC4TARGET}/ncurses/include
	${PROJECT_SOURCE_DIR}/libs/${CC4TARGET}/readline/include
	#eigen
	${PROJECT_SOURCE_DIR}/libs/generic/eigen-3.4.0/include/eigen3/Eigen
)

link_directories(
	${PROJECT_SOURCE_DIR}/libs/${CC4TARGET}/ncurses/lib
	${PROJECT_SOURCE_DIR}/libs/${CC4TARGET}/readline/lib
)

#查找所有.c .cpp源代码文件
file(GLOB_RECURSE 
	SOURCES_CPP
	RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
	CONFIGURE_DEPENDS 
	src/*.c src/*.cpp ${PROJECT_BINARY_DIR}/py_cpp/*.cpp
)

add_executable(${PROJECT_NAME}
	main/main.cpp
	${SOURCES_CPP}
)

target_link_libraries(${PROJECT_NAME}
	${STD_LIBS}
)
